﻿using AutoMapper.Internal.Mappers;
using EMS.system.Entityies.BaseData;
using EMS.system.IEntityAppService.BaseData.IPermissionService;
using EMS.system.IEntityAppService.BaseData.IPermissionService.PermissionDto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.BaseData
{
    public class PermissionController : Controller
    {
        private readonly IPermissionAppService _permissionAppService;

        public PermissionController(IPermissionAppService permissionAppService)
        {
            _permissionAppService = permissionAppService;
        }

        public IActionResult PermissionIndex()
        {
            return View();
        }

        /// <summary>
        /// 权限新增
        /// </summary>
        /// <param name="addDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PermissionAdd(PermissionAddDto addDto)
        {
            return await _permissionAppService.PermissionAdd(addDto);
        }

        /// <summary>
        /// 显示所以权限
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<Permission>> PermissionAllList()
        {
            return await _permissionAppService.PermissionAllList();
        }

        /// <summary>
        /// 显示权限
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<PermissionSelDto>> PermissionList()
        {
            return await _permissionAppService.PermissionList();
        }

        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> PermissionDel(string ids)
        {
            return await _permissionAppService.PermissionDel(ids);
        }

        /// <summary>
        /// 获取单个权限信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<PermissionUpdDto> GetSingPermission(int id)
        {
            return await _permissionAppService.GetSingPermission(id);
        }

        /// <summary>
        /// 编辑权限信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PermissionUpd(PermissionUpdDto dto)
        {
            return await _permissionAppService.PermissionUpd(dto);
        }
    }
}
